/*
 * @Author: your name
 * @Date: 2021-12-23 14:11:57
 * @LastEditTime: 2021-12-23 15:06:11
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: /flutter-learning/Dart_Basic_Grammer/map_list.dart
 */
/**
 * List 里边常用的属性和方法
 * 
 *      常用属性
 *          length
 *          reversed
 *          isEmpty
 *          isNotEmpty
 *      
 *      常用方法
 *          add
 *          addAll
 *          indexOf
 *          remove
 *          removeAt
 *          fillRange
 *          insert(index, value)
 *          insertAll(indexx, list)
 *          toList()
 *          join()      List 转换为字符串
 *          split()
 *          forEach
 *          map
 */

void main(List<String> args) {
    var l1 = <String>['hello', 'world'];
    print(l1);

    List l2 = ['hello', 'world'];
    print(l2);

    l2.add('haha');
    print(l2.length);

    List l3 = List<String>.filled(2, "");
    l3[0] = 'hello';
    l3[1] = 'world';
    print(l3.length);

    print(l2.reversed);
    print(l2.toList());

    // 返回对应元素的索引值, 若没有，那么返回 -1
    print(l2.indexOf("hello"));


    l2.fillRange(1, 2, 'ww');
    print(l2);

    l2.insert(2, 'helloworld');
    print(l2);

    l2.remove("hello");
    print(l2);

    var str = l2.join(',');
    print(str);
    print(str is  String);

    var listt = str.split('-');
    print(listt);

    /**
     * Set {}
     *    用它最主要的功能就是去除数组重复内容
     *    Set 是没有顺序且不能重复的集合，所以不能通过索引去获取值
     */

    var s = new Set();
    s.add("hello");
    s.add("world");

    print(s);

    // list 去重
    var ss = new Set();
    var mylist = ["helllo",  "world", "helllo",  "world",  "helllo",  "world",];

    ss.addAll(mylist);

    print(ss);
    print(ss.toList());



    /**
     * Map
     * 
     *    常用属性
     *        keys
     *        values
     *        isEmpty
     *        isNotEmpty
     * 
     *    常用方法
     *        remove(key)
     *        addAll({...})
     *        containsValue   查看映射内的值 返回 true/false
     *        forEach
     *        map
     *        where
     *        any
     *        every
     */

    var person = {
      "name": "Simon",  
      "age": 20
    };    
    
    var m = new Map();
    m["name"] = "Neal";
    m["age"] = 21;
    
    print(person);
    print(m);

    print(person.keys.toList());
    print(person.values.toList());
    print(person.isEmpty);

    person.addAll({
      "work": ["hello", "world"],
      "sex": "famale"
    });

    print(person);

    person.remove("sex");

    print(person);


    print(person.containsKey("work"));
    print(person.containsValue("famale"));


    for (var i = 0; i < mylist.length; i++) {
      print(mylist[i]);
    }

    person.forEach((key, value) {
      print("$key, $value");
    });

    List li = [1, 2, 3];
    var newList = li.map((value) {
      return value * 2;
    });
    print(newList);


}